package com.kyb.service;

import java.util.ArrayList;
import java.util.List;

import org.junit.Test;

import com.alibaba.fastjson.JSONObject;
import com.kyb.config.Env;
import com.kyb.util.AddressListRegister;
import com.kyb.util.AuthHelper;
import com.kyb.util.DingTalkUtil;

public class MainDemo {

	/***
	 * 注册回调
	 * 
	 * @throws Exception
	 */
	@Test
	public void registerCallBack() throws Exception {
		String accesstoken = AuthHelper.getAccessToken(Env.CORP_ID, Env.CORP_SECRET);
		String token = AddressListRegister.TOKEN;
		String aesKey = AddressListRegister.AES_KEY;
		String callBackUrl = "http://47.99.51.37:8068/dingdata_to_mysql/callbackreceive";
		
		List<String> listStr = new ArrayList<String>();
		listStr.add("user_add_org");
		listStr.add("user_modify_org");
		listStr.add("user_leave_org");

		listStr.add("org_dept_create");
		listStr.add("org_dept_modify");
		listStr.add("org_dept_remove");
		
		JSONObject delCallBack = DingTalkUtil.deleteCallBack(accesstoken);
		System.out.println(delCallBack+"执行成功!");
		
		JSONObject registerCallBack = DingTalkUtil.registerCallBack(accesstoken, listStr, token, aesKey, callBackUrl);
		System.out.println("注册事件返回：" + registerCallBack);

		
		
		System.out.println("accesstoken值为:"+accesstoken);
		JSONObject callBack = DingTalkUtil.getCallBack(accesstoken);
		System.out.println("查询注册事件：" + callBack);
		
		/*JSONObject CallBackFailedResult = DingTalkUtil.getCallBackFailedResult(accesstoken);
		System.out.println("失败结果:"+CallBackFailedResult);*/
		
		
		

	}

	/**
	 * 同步所有人员到数据库
	 * 
	 * @throws Exception
	 */
	@Test
	public void getAllUsersInfo() throws Exception {
		System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog");
		System.setProperty("org.apache.commons.logging.simplelog.showdatetime", "true");
		System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.commons.httpclient", "stdout");
		UserService us = new UserService();
		us.addUsers();

	}

	/**
	 * 同步所有部门信息到数据库
	 * @throws Exception 
	 */
	@Test
	public void getAllDeptInfo() throws Exception {
		System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog");
		System.setProperty("org.apache.commons.logging.simplelog.showdatetime", "true");
		System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.commons.httpclient", "stdout");
		DepartmentServcie ds = new DepartmentServcie();
		ds.addListDepartement();
	}

}
